<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 数组解构赋值
        let [a,b,c,d=20] = [1,2,3] // 如果没有第四个值赋值给d，那么d就取默认值20
        console.log(a,b,c,d)


        // 对象解构复制
        let person = {
            name: "zhangsan",
            age: 22
        }
        let {name, age} = person // 使用对象的属性名进行赋值
        console.log(name, age)
        let {age:dd, name:bb} = person // 给属性名取别名进行赋值
        console.log(bb, dd)


        // 函数解构赋值
        function add([a,b,c=20]) {
            return a+b+c
        }
        console.log(add([1,2,3]))
        console.log(add([1,2]))
    </script>
</head>
<body>
    
</body>
</html>